<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var arr = [1,2,3,4,5,1,2,3]
        //方法1  new Set()
        // var res = Array.from(new Set(arr))
        // console.log(res,"去重结果")
        //方法2  indexOf
        // var res1 = []
        // for(var i = 0 ;i<arr.length-1;i++){
        //     if(res1.indexOf(arr[i])==-1){
        //         res1.push(arr[i])
        //     }
        // }
        // console.log(res1,"数组去重")
        //方法3 filter+index  原理：indexOf会返回最先找到的数字的索引
        var res2=arr.filter((item,index)=>{
            return arr.indexOf(item)===index
        })
        console.log(res2,"数组去重")

    </script>
</head>
<body>
    
</body>
</html>
